#pragma once
#include <pthread.h>    
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <unistd.h>
#include <sys/types.h>

namespace Mymutex
{
class Mutex {
public:
    Mutex() {
        pthread_mutex_init(&mutex, NULL);
    }
    ~Mutex() {
        pthread_mutex_destroy(&mutex);
    }
    void lock() {
        pthread_mutex_lock(&mutex);
    }
    void unlock() {
        pthread_mutex_unlock(&mutex);
    }
    private:

    pthread_mutex_t mutex;
};


class LockGuard {
public:
    LockGuard(Mutex& mutex) : mutex_(mutex) {
        mutex_.lock();
    }
    ~LockGuard() {
        mutex_.unlock();
    }
private:
    Mutex& mutex_;
};
    
} // namespace Mymutex
